<?php

function is_debug_print_on(){
    $obj = new debug_ip_m_core();
    $ci = get_instance();
    $ip = $ci->input->ip_address();
    if(!$obj->valid_debug_ip($ip)) return FALSE;
    return $obj->is_debug_print_on($ip);
}

function is_smarty_console__on(){
    $obj = new debug_ip_m_core();
    $ci = get_instance();
    $ip = $ci->input->ip_address();
    if(!$obj->valid_debug_ip($ip)) return FALSE;
    return $obj->is_smarty_console_on($ip);
}

function is_ignoring_maintenance(){

    $obj = new debug_ip_m_core();
    $ci = get_instance();
    $ip = $ci->input->ip_address();
    if(!$obj->valid_debug_ip($ip)) return TRUE;
    return $obj->is_ignore_maintenance($ip);
}

function debug_dump($var,$trace=FALSE) {
    if(!is_debug_print_on()) return;
    echo ("<br/>-----------------------------------------------------------------<br/>");
    echo "<pre>";
    if($trace) {
        $return = debug_backtrace();
        $string = "<span style='font-weight:bold;color:#9F0000'>FILE</span> <span style='color:green'>".$return[0]['file']."</span> -> <span style='font-weight:bold;color:#9F0000'>CLASS</span> <span style='color:#007F7C'>".$return[1]['class']."</span> -> <span style='font-weight:bold;color:#9F0000'>FUNC</span> <span style='color:#AF008A'>".$return[1]['function']."()</span> -> <span style='font-weight:bold;color:#9F0000'>LINE</span> <span style='color:#0300CF'>".$return[0]['line']."</span>";
        echo $string;
    }
    debug_br();
    debug_br();
    var_dump($var);
    echo "</pre>";
    echo ("<br/>-----------------------------------------------------------------<br/>");
}

function debug_eko($var,$trace=FALSE) {
    if(!is_debug_print_on()) return;
    echo ("<br/>-------------------------------------<br/>");
    if($trace) {
        $return = debug_backtrace();
        $string = "<span style='font-weight:bold;color:#9F0000'>FILE</span> <span style='color:green'>".$return[0]['file']."</span> -> <span style='font-weight:bold;color:#9F0000'>CLASS</span> <span style='color:#007F7C'>".$return[1]['class']."</span> -> <span style='font-weight:bold;color:#9F0000'>FUNC</span> <span style='color:#AF008A'>".$return[1]['function']."()</span> -> <span style='font-weight:bold;color:#9F0000'>LINE</span> <span style='color:#0300CF'>".$return[0]['line']."</span>";
        echo $string;
        debug_br();
        debug_br();
    }

    echo($var);
    echo ("<br/>-------------------------------------<br/>");
}

function debug_h($var,$size=1) {
    if(!is_debug_print_on()) return;
    echo "<h$size>$var</h$size>";
}

function debug_br() {
    if(!is_debug_print_on()) return;
    echo "<br/>";
}

function trace($msg=NULL) {
    if(!is_debug_print_on()) return;
    $return = debug_backtrace();
    $string = "<span style='font-weight:bold;color:#9F0000'>FILE</span> <span style='color:green'>".$return[0]['file']."</span> -> <span style='font-weight:bold;color:#9F0000'>CLASS</span> <span style='color:#007F7C'>".$return[1]['class']."</span> -> <span style='font-weight:bold;color:#9F0000'>FUNC</span> <span style='color:#AF008A'>".$return[1]['function']."()</span> -> <span style='font-weight:bold;color:#9F0000'>LINE</span> <span style='color:#0300CF'>".$return[0]['line']."</span> ". ($msg ? "<span style='color:gray'>[ $msg ]</span>" : "");
    echo $string;
    debug_br();
}
/**
 * Returns TRUE is the current ip address is added  into the debug_ips table
 * @return bool
 */
function has_debug_permission(){
    $ips = explode(";", (string) service_l_core::get_global_setting('debug_console_ips', TRUE));
    if (!in_array(get_instance()->input->ip_address(), array_values($ips))) {
        return FALSE;
    } else {
        return TRUE;
    }
}
/**
 * Returns the last db sql query string
 *
 * @return string
 */
function last_query(){
    return debug_dump(get_instance()->db->last_query(),TRUE);
}

?>